package io.renren.modules.offer.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.CompareUtils;
import io.renren.modules.offer.dao.OfferDao;
import io.renren.modules.offer.entity.OfferEntity;
import io.renren.modules.offer.service.OfferUtilService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @Description
 * @Author haijun.zhang@luckincoffee.com
 * @Date 2018-08-07 18:07
 **/
@Service("offerUtilService")
public class OfferUtilServiceImpl  extends ServiceImpl<OfferDao, OfferEntity> implements OfferUtilService{

    /**
     * 日志
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(OfferUtilServiceImpl.class);
    
    @Override
    public boolean compareEntity(OfferEntity offerEntity, OfferEntity dbOfferEntity) {
        Map<String,Object> map = CompareUtils.getModifyContent(offerEntity,dbOfferEntity);

        if(map.containsKey("name") || map.containsKey("endDate")  || map.containsKey("status")
                || map.containsKey("offerApproval") || map.containsKey("offerApprovalMsg") || map.containsKey("trackingLink") || map.containsKey("pricingType")
                || map.containsKey("payout") || map.containsKey("percentPayout") || map.containsKey("currency") || map.containsKey("previewUrl")
                || map.containsKey("conversionProtoco") || map.containsKey("conversionProtocolMsg") || map.containsKey("thumbnail") || map.containsKey("offerGeo")
                || map.containsKey("offerVbt") || map.containsKey("offerEvent") || map.containsKey("offerPostback") || map.containsKey("offerPlatform")
                || map.containsKey("offerCreative") || map.containsKey("offerCap") || map.containsKey("description")  || map.containsKey("pushStatus")
               // || map.containsKey("category")
                ){
//            for(String key:map.keySet())
//            {
//                LOGGER.info(offerEntity.getSspOfferId()+"  不同点： Key: "+key+" Value:  "+map.get(key));
//            }
            return true;
        }
        return false;
    }

    public static void main(String [] args){
        Date date =new Date();
        OfferEntity offerEntity = new OfferEntity();
        offerEntity.setId(111L);
        offerEntity.setName("offerEntity");
        offerEntity.setEndDate(new Date());

        OfferEntity dbOfferEntity = new OfferEntity();
        dbOfferEntity.setId(1112L);
        dbOfferEntity.setName("offerEntity2");
        dbOfferEntity.setEndDate(new Date(123123123123L));
        Map<String,Object> map = CompareUtils.getModifyContent(offerEntity,dbOfferEntity);
        for(String key:map.keySet())
        {
            LOGGER.info("Key: "+key+" Value: "+map.get(key));
        }
    }


}
